local soundCategories = {
  default = {
    select = "",
    ok = "",
    arrived = "",
    cant = "cantdo4",
    underattack = "units/warning1",
    build = "",  --{ file="lol" },	
    activate = "",  --{ file="lol", volume=1.0 },	
    deactivate = "",  --{"", "", "", file="lol"},
  },

  BUILDING1 = {
    select = "units/stormtl1",
    ok = "",
    arrived = "",
    cant = "cantdo4",
    underattack = "units/warning1",
	  build = "",	
    activate = "",
    deactivate = "",
  },
  
  SHIPYARD1 = {
    select = "units/pshpactv",
    ok = "",
    arrived = "",
    cant = "cantdo4",
    underattack = "units/warning1",
	  build = "",	
    activate = "",
    deactivate = "",
  },
  
  VEHICLE1 = {
    select = "units/tarmsel",
    ok = "units/tarmmove",
    arrived = "units/tarmst0p",
    cant = "cantdo4",
    underattack = "units/warning1",
	  build = "",	
    activate = "",
    deactivate = "",
  },
  
  SHIP1 = {
    select = "units/sharmsel",
    ok = "units/sharmmov",
    arrived = "units/sharmstp",
    cant = "cantdo4",
    underattack = "units/warning1",
	  build = "",	
    activate = "",
    deactivate = "",
  },
}  

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function FixSoundTable (soundTable)
  for name, sound in pairs(soundTable) do
    if (type(sound) == "table" and (not sound[1]) and sound.file) then
      if (sound.volume) then
        soundTable[name] = { [1] = { ["file"] = sound.file, ["volume"] = sound.volume } }
      else   
        soundTable[name] = sound.file
      end
    end	   
  end
end 

for _, category in pairs(soundCategories) do
  FixSoundTable(category)
end

for _, ud in pairs(UnitDefs) do
  -- local params = ud.customparams
  -- if (not params.soundcategory or not soundCategories[params.soundcategory]) then
    -- params.soundcategory = "default"
  -- end
  
  local categoryName = ud.customparams.soundcategory 
  ud.customparams.soundcategory = nil
  if (not categoryName or not soundCategories[categoryName]) then
    categoryName = "default"
  end
  
  local category = soundCategories[categoryName]
  local unitSounds = ud.sounds 
  if (not unitSounds) then
    ud.sounds = category
  else	
    FixSoundTable(unitSounds)
    for name, sound in pairs(category) do
      unitSounds[name] = unitSounds[name] or sound
    end
  end	
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------